<?php
/**
 * mock_fmw_api
 * XHSController.php
 * @author: Heze
 * Date: 2023/4/25 18:53
 */

namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class FmsConfigController extends Controller
{
    public function index(Request $request)
    {
        $method = $request->get('s');
        $method = str_replace('/', '_', trim($method, '/'));

        if (!method_exists($this, $method)) {
            echo sprintf("[%s] mock function not exists", $method);
            exit;
        }

        return $this->$method($request);
    }

    //开票结果回传（正向蓝票开具）
    public function api_fms_config_api_search_ding_user_index(Request $request)
    {
        $name = [
            '何泽001', '何泽002', '何泽003', '何泽004', '何泽005', '何泽006', '何泽007', '何泽008', '何泽009', '何泽0010',
        ];
        $departmentName = [
            '顶级部门', '研发一组', '技术部', '测试一组', '测试部', 'xx部', '产品部',
        ];

        $result = [];
        $mobiles = $request->get('mobiles', []);
        $maxRow = !empty($mobiles) ? count($mobiles) : 10;
        for ($i = 1; $i <= $maxRow; $i++) {
            $randomMobile = sprintf('1%s%s%s', rand(30, 90), rand(1000, 9999), rand(1000, 9999));
            $result[] = [
                "mobile" => !empty($mobiles) ? $mobiles[$i-1] : $randomMobile,
                "main_department_name" => $departmentName[rand(0, count($departmentName) - 1)],
                "ding_user_id" => Str::random(10),
                "name" => $name[rand(0, count($name) - 1)]
            ];
        }

        return $result;
    }

}
